package cn.sdormitory.service.impl;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.service.AppVersionService;
import cn.sdormitory.sys.dao.SysAppVersionDao;
import cn.sdormitory.sys.entity.SysAppVersion;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppVersionServiceImpl implements AppVersionService {

    @Autowired
    SysAppVersionDao versionDao;

    @Override
    public CommonResult compareVersion(SysAppVersion appVersion) {
        QueryWrapper<SysAppVersion> wrapper = new QueryWrapper<>();
        wrapper.eq("app_type",appVersion.getAppType());
        wrapper.orderByDesc("version_no").last("limit 1");
        SysAppVersion sysAppVersion = versionDao.selectOne(wrapper);
        if(sysAppVersion.getVersionNo() > appVersion.getVersionNo()){
            return CommonResult.success(sysAppVersion);
        }else{
           return CommonResult.failed("当前版本为最新版本!");
        }
    }
}
